#:/bin/bash

#Getting snapshot list of Source VM
IFS=$'\n'
echo "Please choose a snapshot:"
i=0 ;for currsnap in `./Get-Snapshots.sh $1`; do snaparr[$i]=$currsnap; 
echo "$i.$currsnap"; i=$(($i +1)) ; done;

#Getting user selection. loop until a valid value has entered.
result=1
while [ $result -ne 0 ]; do
	echo -n "Your selection: "
	read select
	if [ $select -lt $i ]; then
		result=0
	fi
done

echo "Linked cloning snapshot '${snaparr[$select]}' from VM '$1'"

vboxmanage clonevm --snapshot=${snaparr[$select]} --name $2 --options link $1 --register
